<script setup>
import ItemForm from '../components/ItemForm.vue'
import { useRouter } from 'vue-router'
import { useItemStore } from '@/stores/items'

const router = useRouter()
const itemStore = useItemStore()

const handleSubmit = async () => {
  itemStore.addItem({
    id: Date.now(),
    title: formData.title,
    price: formData.price,
    description: formData.description,
  })
  await submitForm()

  router.push('/')
}
</script>

<template>
  <div class="publish-container">
    <h2>发布新商品</h2>
    <ItemForm @add-item="handleAddItem" />
  </div>
</template>

<style scoped>
.publish-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
</style>
